home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / GAUGE.ARJ / UTILS.PAS < prev   
Pascal/Delphi Source File  |  1992-02-13  |  6KB  |  265 lines

  1. {$N+}
  2. unit Utils;
  3. interface
  4.  
  5. uses
  6.   WinTypes, WinProcs, Strings, WinDOS;
  7.  
  8.  
  9. type
  10.   DriveStr = array[0..2] of Char;
  11.   DriveRec = Record
  12.     dLetter : DriveStr;
  13.     dTotal  : LongInt;
  14.   end;
  15.  
  16. var
  17.   avDrives   : array[0..23] of DriveRec;
  18.   dChoice    : Integer;
  19.  
  20.  
  21. function GetHeapSpaces(hModule : THandle) : LongInt;
  22. procedure heapInfo(module : PChar; var pfree, ptotal, ppercent : Word);
  23. function GetFreeResources : LongInt;
  24. procedure SetInternational;
  25. procedure GetCurTime(var tTime : PChar);
  26. procedure GetCurDate(var cDate : PChar);
  27. function OneDriveInfo(drive : Integer; var total : LongInt) : Boolean;
  28. function GetDriveInfo : Integer;
  29. function GetFreeMemory : String;
  30. procedure GetAvail(theDrive : Integer; total : LongInt;
  31.                    var avail : LongInt; var ratio : Single);
  32.  
  33.  
  34. implementation
  35.  
  36. var
  37.   iDate,
  38.   iTime : Integer;
  39.   sDate : array[0..1] of Char;
  40.   sTime : array[0..1] of Char;
  41.   sAMPM : array[0..1, 0..4] of Char;
  42.  
  43. (* -------------  Undocumented Windows function ---------------- *)
  44.  
  45. function GetHeapSpaces(hModule : THandle) : LongInt;
  46.   external 'KERNEL' index 138;
  47.  
  48. (* ------------------------------------------------------------- *)
  49. procedure heapInfo(module : PChar; var pfree, ptotal, ppercent : Word);
  50.   var
  51.     info : LongInt;
  52.   begin
  53.     info := GetHeapSpaces(GetModuleHandle(module));
  54.     pfree := LoWord(info);
  55.     ptotal := Hiword(info);
  56.     info := Word((LongInt(pfree) * 100) div ptotal);
  57.     ppercent := info;
  58.   end;
  59.  
  60. function GetFreeResources : LongInt;
  61.   var
  62.     userFree,
  63.     userTotal,
  64.     userPercent,
  65.     gdiFree,
  66.     gdiTotal,
  67.     gdiPercent : Word;
  68.   begin
  69.     heapInfo('USER', userFree, userTotal, userPercent);
  70.     heapInfo('GDI', gdiFree, gdiTotal, gdiPercent);
  71.     GetFreeResources := MakeLong(userPercent, gdiPercent);
  72.   end;
  73.  
  74.  
  75. procedure SetInternational;
  76.   const
  77.     cName = 'intl';
  78.   begin
  79.     iDate := GetProfileInt(cName, 'iDate', 0);
  80.     iTime := GetProfileInt(cName, 'iTime', 0);
  81.  
  82.     GetProfileString(cName, 'sDate', '/', sDate,     2);
  83.     GetProfileString(cName, 'sTime', ':', sTime,     2);
  84.     GetProfileString(cName, 's1159', 'AM', sAMPM[0], 5);
  85.     GetProfileString(cName, 's2359', 'PM', sAMPM[1], 5);
  86.   end;
  87.  
  88.  
  89. procedure GetCurTime(var tTime : PChar);
  90.   type
  91.     shTime = Record
  92.       shHr  : Word;
  93.       shSep : array[0..1] of Char;
  94.       shMin : Word;
  95.     end;
  96.     lTime = Record
  97.       shHr  : Word;
  98.       shSep : array[0..1] of Char;
  99.       shMin : Word;
  100.       ampm  : PChar;
  101.       {ampm  : array[0..4] of Char;}
  102.     end;
  103.   var
  104.     hr,
  105.     tmin,
  106.     sec,
  107.     hsec  : Word;
  108.     shortTime : shTime;
  109.     longTime  : lTime;
  110.   begin
  111.     GetTime(hr, tmin, sec, hsec);
  112.     with shortTime do begin
  113.       shHr := hr;
  114.       shMin := tmin;
  115.       StrCopy(shSep, sTime);
  116.     end;
  117.     with longTime do begin
  118.       shHr := hr;
  119.       shMin := tmin;
  120.       StrCopy(shSep, sTime);
  121.       GetMem(ampm, 5);
  122.       StrCopy(ampm, sAMPM[hr div 12]);
  123.     end;
  124.     if iTime = 1 then
  125.       begin
  126.         GetMem(tTime, 6);
  127.         wvsprintf(tTime, '%02d%c%02d', shortTime);
  128.       end
  129.     else begin
  130.       GetMem(tTime, 9);
  131.       if (hr mod 12) <> 0 then
  132.         longTime.shHr := hr mod 12
  133.       else
  134.         longTime.shHr := 12;
  135.  
  136.       wvsprintf(tTime, '%02d%c%02d %s', longTime);
  137.     end;
  138.     FreeMem(longTime.ampm, 5);
  139.   end;
  140.  
  141. procedure GetCurDate(var cDate : PChar);
  142.   type
  143.     DateRec = Record
  144.       tday  : Word;
  145.       sep1  : array[0..1] of Char;
  146.       month : Word;
  147.       sep2  : array[0..1] of Char;
  148.       year  : Word;
  149.     end;
  150.   var
  151.     yr,
  152.     mo,
  153.     day,
  154.     dweek   : Word;
  155.     lDate : DateRec;
  156.   begin
  157.     GetMem(cDate, 9);
  158.     {GetMem(lDate.sep1, 2);}
  159.     {GetMem(lDate.sep2, 2);}
  160.     GetDate(yr, mo, day, dweek);
  161.     yr := yr mod 100;
  162.     case iDate of
  163.       1 :
  164.         begin
  165.           with lDate do begin
  166.             tday := day;
  167.             month := mo;
  168.             year := yr;
  169.             StrCopy(sep1, sDate);
  170.             StrCopy(sep2, sDate);
  171.           end;
  172.         end;
  173.  
  174.       2 :
  175.         begin
  176.           with lDate do begin
  177.             tday := yr;
  178.             month := mo;
  179.             year := day;
  180.             StrCopy(sep1, sDate);
  181.             StrCopy(sep2, sDate);
  182.           end;
  183.         end;
  184.  
  185.     else begin
  186.         with lDate do begin
  187.           tday := mo;
  188.           month := day;
  189.           year := yr;
  190.           StrCopy(sep1, sDate);
  191.           StrCopy(sep2, sDate);
  192.         end;
  193.     end;
  194.     end;
  195.     wvsprintf(cDate, '%02d%c%02d%c%02d', lDate);
  196.   end;
  197.  
  198.  
  199. function OneDriveInfo(drive : Integer; var total : LongInt) : Boolean;
  200.   var
  201.     dType : Word;
  202.   begin
  203.     OneDriveInfo := False;
  204.     total := 0;
  205.  
  206.     dType := GetDriveType(drive - 1);
  207.     if (dType >= drive_Removable) then begin
  208.       OneDriveInfo := True;
  209.       total := DiskSize(drive) div 1024 div 1024;
  210.     end;
  211.   end;
  212.  
  213. function GetDriveInfo : Integer;
  214.   var
  215.     i, j  : Integer;
  216.     Total : LongInt;
  217.     isOK  : Boolean;
  218.   begin
  219.     i := 3;
  220.     j := -1;
  221.     isOK := True;
  222.     while isOK do begin
  223.       isOK := OneDriveInfo(i, Total);
  224.       if isOK then begin
  225.         if (Total <> 0) then begin
  226.           Inc(j);
  227.           with avDrives[j] do begin
  228.             dTotal := Total;
  229.  
  230.             dLetter[0] := Chr(i + 64);
  231.             dLetter[1] := ':';
  232.           end;
  233.           Inc(i);
  234.         end
  235.         else
  236.           isOK := False;
  237.       end;
  238.     end;
  239.     GetDriveInfo := j;
  240.   end;
  241.  
  242. function GetFreeMemory : String;
  243.   var
  244.     dwFreeMem : LongInt;
  245.     curMem,
  246.     rMem      : Real;
  247.     temp      : String;
  248.   begin
  249.     dwFreeMem := GetFreeSpace(0);
  250.     curMem := dwFreeMem;
  251.     rMem := curMem / 1024.0 / 1024.0;
  252.     Str(rMem:5:2, temp);
  253.     GetFreeMemory := Concat(temp, ' Mb');
  254.   end;
  255.  
  256.  
  257. procedure GetAvail(theDrive : Integer; total : LongInt;
  258.                    var avail : LongInt; var ratio : Single);
  259.   begin
  260.     avail := DiskFree(theDrive + 3) div 1024 div 1024;
  261.     ratio := Single(avail) / Single(total);
  262.   end;
  263.  
  264. end.
  265.